Add strategy threshold override API with OpenAI suggestion engine#987
Add strategy threshold override API with OpenAI suggestion engine#987
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: adbbd17c6d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| session: Session = Depends(get_session), | ||
| _: dict = Depends(get_current_user), | ||
| ): | ||
| expires_at = payload.market_context_timestamp + payload.recommendation.ttl_minutes * 60 |
There was a problem hiding this comment.
Convert TTL minutes to milliseconds for expiry timestamps
pybinbot.timestamp() is millisecond-based, but this computes expires_at with ttl_minutes * 60 (seconds). As a result, a 60-minute override only lasts about 3.6 seconds when market_context_timestamp is in ms, and the same unit mismatch is repeated in /suggest (expires_at=timestamp() + recommendation.ttl_minutes * 60), so get_active can treat valid overrides as expired almost immediately.
Useful? React with 👍 / 👎.
| session: Session = Depends(get_session), | ||
| _: dict = Depends(get_current_user), | ||
| ): | ||
| client = OpenAiThresholdAdvisor(model=payload.model) |
There was a problem hiding this comment.
Handle advisor initialization errors in suggest endpoint
OpenAiThresholdAdvisor is instantiated before the try block, but its constructor can raise OpenAiThresholdError (for example when OPENAI_API_KEY is unset). In that case /suggest returns an unhandled 500 instead of the intended structured rejection response (error=1), so misconfigured environments fail hard on this route.
Useful? React with 👍 / 👎.
Motivation
Description
strategy_threshold_overrideDB table and Alembic migrationf7b8c9d0e1f2with indexes and a fulldowngradepath.StrategyThresholdOverrideTableSQLModel definition and wire it intodatabases.tables, plus aStrategyThresholdOverrideCrudclass for create/get/list operations.strategy_thresholds.routes(/apply,/suggest,/active, list) and register the router asstrategy_threshold_blueprintinmain.OpenAiThresholdAdvisor, add Pydantic models and guardrails instrategy_thresholds.models, and add config entries and dependency (openaiinpyproject.toml) to support LLM-based suggestions.Testing
pytest api/tests/test_strategy_threshold_overrides.py, which covers applying an override, suggesting with mocked OpenAI (and applying), and rejecting recommendations when guardrails fail, and the tests passed.Codex Task